<?php


namespace app\api\controller\v1;
use app\api\service\Token as TokenService;
use app\api\model\UserAuth as UserAuthModel;

class WechatMsg
{
    /**
     * 发送订阅消息
     */
    public function sendMsg($openid)
    {
        $token = new TokenService();
        $userAuth = UserAuthModel::where('openid',$openid)->find();
        if($userAuth['status'] == 2) {
            $pages = "pages/user/msg_success";
            $data = [
                "thing1" => [
                    "value" => "上墙申请已通过!"
                ],
                "thing4" => [
                    "value" => "审核通过!"
                ],
                "thing5" => [
                    "value" => "点击连接支付费用!"
                ],
                "date7" => [
                    "value" => date("Y-m-d H:i")
                ]
            ];
        } elseif($userAuth['status'] == 3) {
            $pages = "pages/user/update_blind_date";
            $data = [
                "thing1" => [
                    "value" => "上墙申请未通过!"
                ],
                "thing4" => [
                    "value" => "审核未通过!"
                ],
                "thing5" => [
                    "value" => $userAuth['status_con']
                ],
                "date7" => [
                    "value" => date("Y-m-d H:i")
                ]
            ];
        }
        $data = [
            "touser" => $openid,
            "template_id" => "G7qF_cb2hmR1cB66ODWTp8kYnrT4E9j4bn4LLaOw3-I",
            "page" => $pages,
            "miniprogram_state" => "developer",
            "lang" => "zh_CN",
            "data" => $data
        ];
        return $token->sendMsgPub($data);
    }
}